/**
 * Created by Auser on 2017/1/10.
 */
var pwd = new Object({
    setSecCode : function(){
        var secCodeHtml =  '' +
            '<div id="secCodeModal" class="modal fade" tabindex="-1" role="dialog" style="display: none;">'+
                '<div class="modal-dialog">'+
                    '<div class="modal-content">'+
                        '<div class="modal-header">'+
                            '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'+
                            '<h4 class="modal-title">修改安全码</h4>'+
                        '</div>'+
                        '<div class="modal-body">'+
                            '<form class="form-horizontal" id="secCodeForm">'+
                                '<div class="form-group">'+
                                    '<label class="col-sm-3 control-label">原安全码：</label>'+
                                    '<div class="col-sm-9">'+
                                        '<input type="password" id="oldSecCode" />'+
                                    '</div>'+
                                '</div>'+
                                '<!-- 一行开始-->'+
                                '<div class="form-group">'+
                                    '<label class="col-sm-3 control-label">新安全码：</label>'+
                                    '<div class="col-sm-9">'+
                                        '<input type="password" id="newSecCode" />'+
                                    '</div>'+
                                '</div>'+
                                '<!-- 一行开始-->'+
                                '<div class="form-group">'+
                                    '<label class="col-sm-3 control-label">确认安全码：</label>'+
                                    '<div class="col-sm-9">'+
                                        '<input type="password" id="confirmSecCode" />'+
                                    '</div>'+
                                '</div>'+
                            '</form>'+
                            '<div class="modal-footer" style="text-align:center">'+
                                '<button type="button" class="btn btn-primary"  onclick="pwd.setSecCodeSubmit()" >确认</button>'+
                                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
                            '</div>' +
                    '</div>'+
                '</div>'+
            '</div> ';

        document.body.appendChild($(secCodeHtml)[0]);
        $('#secCodeModal').on('hidden.bs.modal', function () {
            document.body.removeChild($('#secCodeModal')[0]);
        });
        $('#secCodeModal').modal('show');
    },setPwd : function(){
        var pwdHtml =  '' +
            '<div id="pwdModal" class="modal fade" tabindex="-1" role="dialog" style="display: none;">'+
                '<div class="modal-dialog">'+
                    '<div class="modal-content">'+
                        '<div class="modal-header">'+
                            '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'+
                            '<h4 class="modal-title">修改密码</h4>'+
                        '</div>'+
                        '<div class="modal-body">'+
                            '<form class="form-horizontal" id="pwdForm">'+
                                '<div class="form-group">'+
                                    '<label class="col-sm-3 control-label">原密码：</label>'+
                                    '<div class="col-sm-9">'+
                                        '<input type="password" id="oldPwd" />'+
                                    '</div>'+
                                '</div>'+
                                '<!-- 一行开始-->'+
                                '<div class="form-group">'+
                                    '<label class="col-sm-3 control-label">新密码：</label>'+
                                    '<div class="col-sm-9">'+
                                        '<input type="password" id="newPwd" />'+
                                    '</div>'+
                                '</div>'+
                                '<!-- 一行开始-->'+
                                '<div class="form-group">'+
                                    '<label class="col-sm-3 control-label">确认密码：</label>'+
                                    '<div class="col-sm-9">'+
                                        '<input type="password" id="confirmPwd" />'+
                                    '</div>'+
                                '</div>'+
                            '</form>'+
                            '<div class="modal-footer" style="text-align:center">'+
                                '<button type="button" class="btn btn-primary"  onclick="pwd.setPwdSubmit()" >确认</button>'+
                                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
                            '</div>' +
                    '</div>'+
                '</div>'+
            '</div> ';

        document.body.appendChild($(pwdHtml)[0]);
        $('#pwdModal').on('hidden.bs.modal', function () {
            document.body.removeChild($('#pwdModal')[0]);
        });
        $('#pwdModal').modal('show');
    },
    setSecCodeSubmit:function(){
        var oldSec = $('#oldSecCode').val();
        var newSec = $('#newSecCode').val();
        var confirmSec = $('#confirmSecCode').val();
        $.ajax({
            url:contextPath + '/user/pwd/setSecCode',
            data:{oldSecCode:oldSec,newSecCode:newSec,confirmSecCode:confirmSec},
            type:'POST',
            //data:$('#secCodeForm').serialize(),
            success:function(res){
                if(res.meta.success){
                    alert_message(res.data);
                    $('#secCodeModal').modal('hide');
                }else{
                    alert_message(res.meta.message);
                }
            }
        })
    },
    setPwdSubmit:function(){
        var oldPwd = $('#oldPwd').val();
        var newPwd = $('#newPwd').val();
        var confirmPwd = $('#confirmPwd').val();

        $.ajax({
            url:contextPath + '/system/user/pwd/setPwd',
            data:{oldPwd:oldPwd,newPwd:newPwd,confirmPwd:confirmPwd},
            type:'POST',
            //data:$('#pwdForm').serialize(),
            success:function(res){
                if(res.meta.success){
                    alert_message(res.data);
                    $('#pwdModal').modal('hide');
                }else{
                    alert_message(res.meta.message);
                }
            }
        })
    }
})